// 页面路径：store/index.js
import {
	createStore
} from 'vuex'
const store = createStore({
	state: {
		sTime: '',
		eTime: '',
		deviceId: '',
		serviceId: '',
		characteristicId: '',
		carId: '',
		rfidMsgo: {},
		rfidMsgt: {},
		msg: {},
		allData: {},
		useCarId: 0,
		sendMsg: {},
		isLogin: 1,
		lanId: '1', //蓝牙id
		lanLight: '', //蓝牙光照
		lanValue: '', //蓝牙光照阈值
		lanSpeed: '', //蓝牙转速
		lanLocation: '', //蓝牙位置
		allDevice: [],
		// allDevice: [{
		// 	id: 'zql'
		// }, {
		// 	id: 'wb'
		// }],
		user: {
			account: 'hlxx',
			status: 1, // 用户身份  0 为非法用户  1为合法用户
			use: 1, // 0表示未在骑行  1表示在骑行中
		},
		covers: [{
				id: 1,
				latitude: '',
				longitude: '',
				iconPath: '/static/images/car.png'
			},
			{
				id: 2,
				latitude: '',
				longitude: '',
				iconPath: '/static/images/car.png'
			}
		],
	},

	mutations: {
		setAllDeviceNull(state, value) {
			state.allDevice = []
		},
		setUserAccount(state, value) {
			state.user.account = ''
			state.user.account = value
		},
		setSTime(state, value) {
			state.sTime = ''
			state.sTime = value
		},
		setETime(state, value) {
			state.eTime = ''
			state.eTime = value
		},
		setCharacteristicId(state, value) {
			state.characteristicId = ''
			state.characteristicId = value
		},
		setDeviceId(state, value) {
			state.deviceId = ''
			state.deviceId = value
		},
		setServiceId(state, value) {
			state.serviceId = ''
			state.serviceId = value
		},
		setLanId(state, value) {
			state.lanId = ''
			state.lanId = value
		},
		setLanLight(state, value) {
			state.lanLight = ''
			state.lanLight = value
		},
		setLanValue(state, value) {
			state.lanValue = ''
			state.lanValue = value
		},
		setLanSpeed(state, value) {
			state.lanSpeed = ''
			state.lanSpeed = value
		},
		setLanLocation() {
			state.lanLocation = ''
			state.lanLocation = value
		},
		setRfidMsgo(state, value) {
			state.rfidMsg = ''
			state.rfidMsg = value
		},
		setRfidMsgt(state, value) {
			state.rfidMsgt = ''
			state.rfidMsgt = value
		},
		setAllData(state, value) {
			state.allData = ''
			state.allData = value
		},
		setAllDevice(state, value) {
			let length = state.allDevice.length
			let i = 0;
			for(; i < length; i++){
				if(state.allDevice[i].id==value) {
					break
				}
			}
			console.log(i);
			if(i==length) {
				let temp = {id: value}
				state.allDevice.push(temp)
			}
			console.log(state.allDevice);

		},
		setCarId(state, value) {
			console.log(value);
			console.log(state.carId);
			state.carId = ''
			state.carId = value
		},
		setMsg(state, msg) {
			state.msg = ''
			state.msg = msg
		},
		setUserUse(state, value) {
			state.user.use = ''
			state.user.use = value
		},
		setUserStatus(state, value) {
			state.user.status = ''
			state.user.status = value
		},
		setUseCarId(state, value) {
			state.useCarId = ''
			state.useCarId = value
		},
		setId(state, i) {
			state.allData[i].id = ''
			state.allData[i].id = i
		},
		setIsLogin(state, value) {
			state.isLogin = ''
			state.isLogin = value
		},
		setSendMsg(state, msg) {
			state.sendMsg = ''
			state.sendMsg = msg
		},

		// 缓存登陆用户信息
		login(state, user) {
			state.user = user
			// 缓存用户信息
			// 先脱敏

			uni.setStorageSync('user', JSON.stringify(user))
		},
		logout(state) {
			state.user = null
			// 清理缓存用户信息
			uni.removeStorageSync('user')
		}
	}
})

export default store
